import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;

public class ButtonApplication extends JFrame implements ActionListener {
    private int clickOkCount = 0;
    private int clickCancelCount = 0;

    private JButton okButton;
    private JButton cancelButton;

    public ButtonApplication() {
        super("Button Application");

        // 使用 BorderLayout 布局
        setLayout(new BorderLayout(5, 5));

        // 创建并设置按钮
        okButton = new JButton("确定");
        okButton.addActionListener(this);

        cancelButton = new JButton("取消");
        cancelButton.addActionListener(this);

        // 使用 FlowLayout 布局将按钮放在下面
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        buttonPanel.add(okButton);
        buttonPanel.add(cancelButton);

        // 将按钮面板添加到容器的南部
        add(buttonPanel, BorderLayout.SOUTH);

        setSize(300, 200);
        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == okButton) {
            clickOkCount++;
            repaint();
        } else if (e.getSource() == cancelButton) {
            clickCancelCount++;
            repaint();
        }
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        g.setColor(Color.GREEN);
        g.drawString("点击确定次数: " + clickOkCount, 100, 80);

        g.setColor(Color.RED);
        g.drawString("点击取消次数: " + clickCancelCount, 100, 100);
    }

    public static void main(String[] args) {
        new ButtonApplication();
    }
}